package com.fvff.sanctuary.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.CollectionOfElements;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * Album
 */
@Entity(name = "ALBUM")
public final class Album implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "Activity_ID")
    private Long id;

    @Column(name = "DESCRIPTION")
    private String description;

    @Column(name = "OPEN_SOCIAL_ID")
    private String openSocialId;

    @OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @JoinColumn(name = "LOCATION_ID")
    private Address location;

    @Column(name = "MEDIA_ITEM_COUNT")
    private Integer mediaItemCount;

    @Column(name = "MEDIA_MIME_TYPES")
    @CollectionOfElements(fetch = FetchType.LAZY)
    private Set<MediaItemType> mediaItemTypes = new HashSet<MediaItemType>();

    @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = "album")
    private Set<MediaItem> mediaItems = new HashSet<MediaItem>();

    @ManyToOne
    @JoinColumn(name = "PERSON_ID")
    private Person person;

    @ManyToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @JoinColumn(name = "THUMBNAIL_URL_ID")
    private Url thumbnailUrl;

    @Column(name = "TITLE")
    private String title;

    public Long getId() {
        return id;
    }

    public void setId(final Long id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(final String description) {
        this.description = description;
    }

    public String getOpenSocialId() {
        return openSocialId;
    }

    public void setOpenSocialId(final String openSocialId) {
        this.openSocialId = openSocialId;
    }

    public Address getLocation() {
        return location;
    }

    public void setLocation(final Address location) {
        this.location = location;
    }

    public Integer getMediaItemCount() {
        return mediaItemCount;
    }

    public void setMediaItemCount(final Integer mediaItemCount) {
        this.mediaItemCount = mediaItemCount;
    }

    public Set<MediaItemType> getMediaItemTypes() {
        return mediaItemTypes;
    }

    public void setMediaItemTypes(final Set<MediaItemType> mediaItemTypes) {
        this.mediaItemTypes = mediaItemTypes;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(final Person person) {
        this.person = person;
    }

    public Url getThumbnailUrl() {
        return thumbnailUrl;
    }

    public void setThumbnailUrl(final Url thumbnailUrl) {
        this.thumbnailUrl = thumbnailUrl;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(final String title) {
        this.title = title;
    }

    @Override
    public boolean equals(final Object o) {
        return o != null && (o == this || o.getClass() == getClass() && EqualsBuilder.reflectionEquals(this, o));
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append("id", id).
                append("openSocialId", openSocialId).
                append("title", title).
                append("description", description).
                append("person", person).
                toString();
    }
}
